<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    body {
      margin: 0;
    }
    #cvs {
      height: 100vh;
      width: 100vw;
    }
  </style>
</head>
<body>
  <canvas id="cvs"></canvas>
  <script>

    const cvs = document.querySelector('#cvs');

    const ctx = cvs.getContext('2d'); // webgl

    //创建图片
    const imageInstance = new Image(100, 100);
    //设置图片地址
    imageInstance.src = 'file:///Users/yuu/Pictures/bug.png';

    ctx.mozImageSmoothingEnabled = false;
    ctx.webkitImageSmoothingEnabled = false;
    ctx.msImageSmoothingEnabled = false;
    ctx.imageSmoothingEnabled = false;

    // 必须要在onLoad之后再进行绘制图片，否则不会渲染
    imageInstance.onload = () => {
        console.log(imageInstance.width);
        console.log(imageInstance.height);
        //4各参数 图片的起始坐标和宽高
        ctx.drawImage(imageInstance, 0, 0, 100, 100);

    };

  </script>
</body>
</html>